﻿using LuaInterface;
using System.Collections;
using System;

public class LuaProc : Proc
{
    public string LuaClassName;

    private LuaTable mLuaObject;
    public LuaTable LuaObject
    {
        get
        {
            return mLuaObject;
        }
    }

    void CallLuaFunction(string funcName, params object[] args)
    {
        if (this.mLuaObject == null)
            return;

        LuaFunction func = this.mLuaObject[funcName] as LuaFunction;
        if (func != null)
            func.Call(mLuaObject, args);
    }

    public LuaProc(LuaTable luaProc)
    {
        mLuaObject = luaProc;
    }

    public override string type
    {
        get
        {
            return this.mLuaObject.GetStringField("__cname");
        }
    }

    public override void onBegin(object[] additionalParams)
    {
        CallLuaFunction("onBegin", additionalParams);
    }

    public override void process()
    {
        CallLuaFunction("process");
    }

    public override void fixedUpdate()
    {
        CallLuaFunction("fixedUpdate");
    }

    public override void onEnd()
    {
        CallLuaFunction("onEnd");
        if(mLuaObject != null)
        {
            mLuaObject.Dispose();
        }
    }

}
